#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
package ${package}.${artifactId}.data.dao;

import ${package}.${artifactId}.data.mapper.BaseMapper;
import ${package}.${artifactId}.data.model.BaseDO;
import ${package}.${artifactId}.enums.DelEnum;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.PostConstruct;
import java.util.List;

/**
 * @Author: shenyang
 * @CreateTime: 2023-01-16  15:42
 * @Description: TODO
 * @Version: 1.0
 */
public abstract class BaseDAOImpl<T extends BaseDO, CustomMapper extends BaseMapper<T>> implements BaseDAO<T> {


    private CustomMapper baseMapper;

    @PostConstruct
    public void initMapper() {
        this.baseMapper = getCustomMapper();
    }

    public abstract CustomMapper getCustomMapper();

    @Override
    public int save(T t) {
        return baseMapper.insertSelective(t);
    }

    @Override
    public int saveAll(List<T> list) {
        return baseMapper.insertList(list);
    }

    @Override
    public int delete(T t) {
        return baseMapper.delete(t);
    }


    @Override
    public int deleteById(Integer integer) {
        return baseMapper.deleteByPrimaryKey(integer);
    }

    @Override
    public int update(T t) {
        return baseMapper.updateByPrimaryKey(t);
    }

    @Override
    public int updateAll(List<T> t) {
        return baseMapper.updateBatchByPrimaryKeySelective(t);
    }


    @Override
    public T getById(Integer integer) {
        return baseMapper.selectByPrimaryKey(integer);
    }

    @Override
    public List<T> getAll() {
        return baseMapper.selectAll();
    }

    @Override
    public List<T> searchByExample(Example example) {
        return baseMapper.selectByExample(example);
    }

    @Override
    public T selectOneByExample(Example example) {
        return baseMapper.selectOneByExample(example);
    }

    @Override
    public T selectOneNotDelByExample(Example example) {
        example.and().andEqualTo(BaseDO.DEL, DelEnum.NOT_DEL);
        return baseMapper.selectOneByExample(example);
    }
}
